package cn.bluech.lib.utils;

import android.text.TextUtils;

import java.security.MessageDigest;

/**
 * Description:
 * Date: 2020/11/17.
 */
public class Md5Util {
    public static String getMd5(byte[] source) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(source);
            byte[] md5 = digest.digest(); // 128 bit(16字节)
            // 库接口带有空格分割，暂时在这里去除
            return ByteUtils.toHex(md5).toLowerCase();
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getMd5(String source) {
        if(TextUtils.isEmpty(source))
            return "";
        return getMd5(source.getBytes());
    }
}
